/*
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * This file is part of Harmattan SmashMiner OpenGL game application.
 * 
 * Harmattan SmashMiner OpenGL Example Application version 1.0.0
 *  
 * Latest update: 15.4.2011
 *
 * The Harmattan SmashMiner OpenGL example application demonstrates how to use 
 * the OpenGL ES in Harmattan devices.
 *
 * This example is provided as a starting point for 3rd party
 * developers (you) to ease the implementation of OpenGL based 
 * games. Ideas, parts of code or methodologies that this
 * example application uses can be freely used without restrictions.
 *
 * See file README.txt how to build and compile this example application
 * in the Harmattan SDK environment. 
 * 
 * See file INSTALL.txt to find out what is required to run this
 * application and how to install the application to the device or
 * alternatively in QEMU-emulator.
 *
 * The LICENSE.txt file explains the license this software is provided
 * with. A copy of the same license is included in this source file.
 * 
 */

/*
 * Copyright (C) 2011 by Nokia Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/**
\file Settings.qml
\brief This is the settings view of the SmashMiner game.

See the \c settingsView at the main.qml view.

\sa main.qml
*/

import Qt 4.7

Rectangle {
    id: settingsView

    // Signal to return main view
    signal back()

    // Vertical margins of the view area
    property int marginsVertical: height/20
    // Height of the view header
    property int headerHeight: marginsVertical*2
    // Horizontal margins of the view area
    property int marginsHorizontal: headerHeight+marginsVertical
    // Height of the buttons used at this view
    property int buttonHeight: headerHeight*0.9
    // Width of the buttons used at this view
    property int buttonWidth: buttonHeight*2.5


    width: parent.width
    height: parent.height
    color: "black"
    z: -10
    visible: true

    Image {
        id: background

        anchors.fill: parent
        source: "qrc:/images/1024x512_01.jpg"
    }


    ViewHeader {
        id: settingsHeader
        heading: qsTr("SETTINGS")
    }

    Rectangle {
        id: rectangleSettings

        width: parent.width
        anchors { left: parent.left; right: parent.right; leftMargin: marginsHorizontal; rightMargin: marginsHorizontal;
            top: settingsHeader.bottom; bottom: settingsFooter.top }
        color: "black"
        border { width: 5; color: "#333333" }

        // 2 column and 5 row frid for the setting items. Column 1 for text and 2 for control.
        Grid {
            id: settingsGrid

            // Width of the setting label
            property int labelWidth: (width-marginsHorizontal)*0.3
            // Width of the setting control
            property int controlWidth: (width-marginsHorizontal)*0.7

            rows:  5
            columns: 2
            spacing: marginsVertical/2
            anchors { top: parent.top; topMargin: marginsVertical; left: parent.left; leftMargin: marginsHorizontal/2;
                right: parent.right; rightMargin: marginsHorizontal/2; bottom: parent.bottom; bottomMargin: marginsVertical }

            Text {
                width: settingsGrid.labelWidth
                height: buttonHeight
                text: qsTr("Music Level")
                color: "lightgrey"
                font.pointSize: 14
            }
            Slider {
                id: musicSlider
                width: settingsGrid.controlWidth
                height: buttonHeight
                onPressingChanged: {
                    if(!pressing)
                        gameSettings.musicLevel = value;
                }
                Component.onCompleted: {
                    value = gameSettings.musicLevel;
                }
            }

            Text {
                width: settingsGrid.labelWidth
                height: buttonHeight
                text: qsTr("Sound Effects Level")
                color: "lightgrey"
                font.pointSize: 14
            }
            Slider {
                id: soundSlider
                width: settingsGrid.controlWidth
                height: buttonHeight
                onPressingChanged: {
                    if(!pressing)
                        gameSettings.soundLevel = value;
                }
                Component.onCompleted: {
                    value = gameSettings.soundLevel;
                }
            }

            Text {
                width: settingsGrid.labelWidth
                height: buttonHeight
                text: qsTr("Difficulty")
                color: "lightgrey"
                font.pointSize: 14
            }

            Grid {
                id: difficultySelector

                width: settingsGrid.controlWidth
                height: buttonHeight
                rows: 1
                columns: 3
                spacing: 10

                Button {
                    id: difficultyLevel1

                    width: buttonWidth
                    height: buttonHeight
                    label: qsTr("Easy")
                    pressed: gameSettings.difficultyLevel == 1
                    onClicked: gameSettings.difficultyLevel = 1
                }

                Button {
                    id: difficultyLevel2

                    width: buttonWidth
                    height: buttonHeight
                    label: qsTr("Medium")
                    pressed: gameSettings.difficultyLevel == 2
                    onClicked: gameSettings.difficultyLevel = 2;
                }

                Button {
                    id: difficultyLevel3

                    width: buttonWidth
                    height: buttonHeight
                    label: qsTr("Hard")
                    pressed: gameSettings.difficultyLevel == 3
                    onClicked: gameSettings.difficultyLevel = 3
                }
            } // Grid difficultySelector

            Text {
                width: settingsGrid.labelWidth
                height: buttonHeight
                text: qsTr("Left handed")
                color: "lightgrey"
                font.pointSize: 14
            }
            Switch {
                id: leftHandedSwitch

                width: buttonWidth
                height: buttonHeight
                onOnChanged: gameSettings.leftHanded = leftHandedSwitch.on
                Component.onCompleted: {
                    if (gameSettings.leftHanded) {
                        leftHandedSwitch.state = "on";
                    }
                    else {
                        leftHandedSwitch.state = "off";
                    }
                }
            }

            Text {
                width: settingsGrid.labelWidth
                height: buttonHeight
                text: qsTr("Rewind")
                color: "lightgrey"
                font.pointSize: 14
            }

            Switch {
                id: rewindSwitch

                width: buttonWidth
                height: buttonHeight
                onOnChanged: gameSettings.endRewind = rewindSwitch.on
                Component.onCompleted: {
                    if (gameSettings.endRewind) {
                        rewindSwitch.state = "on";
                    }
                    else {
                        rewindSwitch.state = "off";
                    }
                }
            }
        } // Grid
    }

    ViewFooter {
        id: settingsFooter

        width: parent.width
        height: headerHeight

        onBackClicked: {
            gameSettings.save();
            soundEngine.playMenuSound();
            back();
        }
    } // settingsFooter
}
